package com.smart.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.manage.domain.DrugStock;
import com.smart.manage.service.IDrugStockService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 药品库存管理Controller
 * 
 * @author lingyao
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/manage/drugStock")
public class DrugStockController extends BaseController
{
    @Autowired
    private IDrugStockService drugStockService;

    /**
     * 查询药品库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:drugStock:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugStock drugStock)
    {
        startPage();
        List<DrugStock> list = drugStockService.selectDrugStockList(drugStock);
        return getDataTable(list);
    }

    /**
     * 导出药品库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:drugStock:export')")
    @Log(title = "药品库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugStock drugStock)
    {
        List<DrugStock> list = drugStockService.selectDrugStockList(drugStock);
        ExcelUtil<DrugStock> util = new ExcelUtil<DrugStock>(DrugStock.class);
        util.exportExcel(response, list, "药品库存管理数据");
    }

    /**
     * 获取药品库存管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:drugStock:query')")
    @GetMapping(value = "/{stockId}")
    public AjaxResult getInfo(@PathVariable("stockId") Long stockId)
    {
        return success(drugStockService.selectDrugStockByStockId(stockId));
    }

    /**
     * 新增药品库存管理
     */
    @PreAuthorize("@ss.hasPermi('manage:drugStock:add')")
    @Log(title = "药品库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugStock drugStock)
    {
        return toAjax(drugStockService.insertDrugStock(drugStock));
    }

    /**
     * 修改药品库存管理
     */
    @PreAuthorize("@ss.hasPermi('manage:drugStock:edit')")
    @Log(title = "药品库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugStock drugStock)
    {
        return toAjax(drugStockService.updateDrugStock(drugStock));
    }

    /**
     * 删除药品库存管理
     */
    @PreAuthorize("@ss.hasPermi('manage:drugStock:remove')")
    @Log(title = "药品库存管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockIds}")
    public AjaxResult remove(@PathVariable Long[] stockIds)
    {
        return toAjax(drugStockService.deleteDrugStockByStockIds(stockIds));
    }
}
